.content_comment
  #loading_indicator{:style=>"display:none"}
    =image_tag("ajax-loader.gif")
  .profile_pic
    =fb_profile_pic(@current_user.fb_uid, {:size=>"square"})
  .comment_area
    %textarea{:class=>"comment_box", :id=>"comment_text_area"}
      =t(:comment_area_text)
  .content_comment_actions
    %input{:class=>"fb_button", :style=>"display:none", :id=>"post_comment_button", :type=>"submit", :value=>"#{t(:comment)}"}    

%script{:type => "text/javascript", :charset => "utf-8"}    
  var default_comment_message = "#{t(:comment_area_text)}"
  post_url = "#{post_url}";
  :plain
    
    comment_area = $('comment_text_area');
    post_comment_button = $('post_comment_button');
    post_comment_button.addEventListener('click', function() {
      if (comment_area.getValue().trim() == "" || comment_area.getValue().trim() ==  default_comment_message) {
        fb_message("Error", "Noting to post");
      } else {
        postComment();
        
      }
    });
    comment_area.addEventListener('focus', function() {
       if (comment_area.getValue() == default_comment_message) {
         comment_area.setValue("");
         post_comment_button.show();
       }
       
    });
    
    comment_area.addEventListener('blur', function() {
       if (comment_area.getValue().trim() == "") {
         post_comment_button.hide();
         comment_area.setValue(default_comment_message);
       }
         
    });
    
    function postComment() {
      $('loading_indicator').show();
      
      var ajax = new Ajax();
      ajax.responseType = Ajax.FBML;
    
      ajax.ondone = function(data){
        $('loading_indicator').hide();
        
        comments_container = $('content_comments_container');
        //comments_container.append(data);
        var newDiv = document.createElement('div');
        //new_data = data.replace(/&lt;br&gt;/gi,'<br>');
        //fb_message("data",data);
        
        newDiv.setInnerFBML(data);
        post_comment_button.hide();
        
        comments_container.appendChild(newDiv)
        //fb_message("new_data",newDiv.getInnerFBML());
        comment_area.setValue(default_comment_message);
      }
      comment_value = comment_area.getValue().replace(/\n/gi,'<br>\n').trim();
      //fb_message("kkk",comment_value);
      post_params = {"comment" : {"comment" : comment_value } };
      ajax.post(post_url,post_params);
    }
    
     
